import axios from 'axios';
import {ElMessage} from "element-plus";

//创建axios实例
const Service=axios.create({
    baseUrl:' http://localhost:8081',
    //定义统一的请求头
    headers:{
        'Content-Type':"application/json;charset=UTF-8"
    },
    //配置请求超时时间
    time:10000
})
//请求拦截器
Service.interceptors.request.use((config)=>{
    config.headers.common['Authorization']=window.localStorage.getItem('token')===null?null:'Bearer'+window.localStorage.getItem('token')
    return config

})
//配置响应拦截器
Service.interceptors.response.use((response)=>{
    const  res=response.data
    if(res.status===0){
        return res
    }
    else{
        ElMessage.error(res.message||'网络异常')
        return res
    }
})
export default Service